package day13;

import java.io.File;
import java.io.IOException;

public class FileDem {
    public static void main(String[] args) {
        creatFile("/Users/jinnian/Desktop/file1");
        creatFolder("/Users/jinnian/Desktop/file1");
    }

    private static void creatFolder(String pathname) {
        File file=new File(pathname);
        if(!file.exists()){
            if(file.mkdirs()){
                System.out.println("目录创建成功");
            }else {System.out.println("目录创建失败了");}
        }else {
            System.out.println("已经存在了");

        }
    }

    private static void creatFile(String pathname) {
        File file=new File(pathname);
        if(!file.exists()){
            try {
                if(file.createNewFile()){
                    System.out.println("项目创建成功");
                    System.out.println(""+file.getName());
                    System.out.println(""+file.getAbsolutePath());
                    System.out.println(""+file.getPath());
                    System.out.println(""+file.length());
                    System.out.println(""+file.getParent());
                    System.out.println(file);


                }else {
                    System.out.println("项目创建失败");
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        else {
            System.out.println("文件已经存在了");
        }
    }

}
